const {
  rootPath,
  API,
  HomePath
} = require("../../utils/const")
const {
  postLogin,
  getRequest,
  requestUserInfo
} = require("../../utils/request")

const dateUtils = require("../../utils/dateUtils")

Page({
  data: {
    material: {},
    materialBaseInfo: {}
  },

  onLoad: function(options) {
    const materialId = options.id;
    this.fetchMaterialDetail(materialId);  
  },

  fetchMaterialDetail: function(id) {
    const that = this;
    getRequest(API.getMaterialById + '/' + id).then(res => {
      that.setData({
        material: res
      }, () => {
        const materialId = that.data.material.materialId;
        getRequest(API.getMaterialBaseInfoById + '/' + materialId).then(resplus => {
          that.setData({
            materialBaseInfo: resplus
          });
        });

        const material = that.data.material;
        material.sendTime = dateUtils.formatComplaintTime(material.sendTime);
        that.setData({
          material: material
        })
      });
    });
  }
});